

package com.hazelcast.jet.impl.util;

import com.hazelcast.function.FunctionEx;

import java.io.Serial;

/**
 * A function returning a constant.
 * <p>
 * This is a trivial lambda, but we want to be able to do instanceof check on
 * it to be able to do some optimizations.
 */
public class ConstantFunctionEx<T, R> implements FunctionEx<T, R> {

    @Serial
    private static final long serialVersionUID = 1L;

    private final R key;

    public ConstantFunctionEx(R key) {
        this.key = key;
    }

    @Override
    public R applyEx(T t) {
        return key;
    }
}
